bug fixes and cleaning