refactor & added javadoc