added javadoc and few bugfixes