Bugfixes & refactoting