added javadoc and improved code formatting