Documentation and cleaned up code a bit