Refactoring and bugfixing

Logging improved
Add "final"