Added more comments and javadoc.