Fix regression and slight optimization

This fixes the JVM regression.