Clean up and fix bugs