bug fixes and removal of bad code