Adding proper headers to responses
-Also cleaning up code