http.c refactored