improved HTTP logic