clean up some of the mess aka bug fixing and removing unused code