Clean code and add javadoc