Added some input checking and javadoc.