Big fixes and Cleanup of unneeded code