Ruling gives churches leeway under handgun law