bug fixes and some clean up