bug fixes and cleaning up code