cleanup and minor bug fixes