Added non-blocking option, custom header support, more comments and cleaned code.