improve code and javadoc