Optimize references. Fixes #1