added javadoc, refactoring, fixes