Simplify and add javadocs. See issue 432.