Bug fix and code improvements

* Fixed #39
* Improved code style (linted), logging and flow-control management