Add Javadoc and simplify code.