tidying up code, javadoc and fixing typos.