Make code more pythonic and change http code check