Bugfixes and debugging stuff