More fixes and clean up of code