added JavaDocs and cleaned up code for better readability