simplify http by moving code into handlers