Cleaning up and bugfixes