cleaned up code and wrote a shit load of documentation