several bug fixes and clean up