Javadocing and slight refactoring