Adding documentation and cleaning up code.