Cleanup and minor bug fixes