Refactor and update javadocs