Added additional javadoc and added further tests. Reorgnaized code.