Major clean up and test fix