Bugfixes and refactoring
Formatting