Bugfixes
Some bug fixes and cleanups