Added more tests and javadoc comment and addressed issues flagged by static analysis.