More robust tests and add more javadoc