Cleaned the code (somewhat) and added mountains of JavaDoc