restructuring http handling