Added a little documentation and cleaned up the code.