Cleaned the code and added mountains of JavaDoc