A lot of cleanup and test fixing