some comments and javadocs added. nearly identical methods merged.