restructured code and added proper http handlers