Refactoring entry point
Fix exception code.
Error handling
Setup logging level for error exceptions
Fixed: clearing buffer
Register logger writer before error handler
Other minor fixes