Clean up code and add some minor features