Bug fix and small changes. Some Javadoc.