Refactored for comprehension and improved javadoc.