Make this more generic and fix javadoc