moving code to prevent verbosing before headers are sent