Clean up the code and add more docs.