Clean up and minor bugfixes