initial pass at refactoring reference.jl