Cleanup and fix tests