more fixes and cleaning up of code