a few bug fixes and some cleanup.