Fixes 619 take2

Supersedes pull #700, this was definitely a better idea @aembler

And for references, this fixes #619