Small refactoring

* Moved logic to lib folder
* Added console mode
* Some small improvements