Bugfixes

Mostly Bugfixes
Automatic code formatting was done with CodeMaid