Added javadoc comments and improved code formatting