Added some documentation and cleaned the file a bit