refactor code for http