Added more javadoc and cleaned up code.