A bit refactoring and bugfixing, started callback implementation