changed error handling and http handling logic