minor bug fixes and code clean up