More efficient code, code style improvements.

Style of code improved, error reporting, timeout for HTTP clients.