Added comments

Added comments and javadocs in various places.