Refactor the code and add comments with JavaDocs

-Refactor the code, optimize imports, etc.
-Write JavaDocs for the classes that were missing it
-Write comments everywhere where they are needed