Added support for PUT and DELETE calls, added logging out on error, added logout function, cleaned up code