Added some missing javadoc and did some refactoring