Some cleanup and test fixes