pass variables directly to subroutines
removed redudant code, added content type header