restricted references can create implicit mappings (#1465)
fix test
refactor resolveRef
tidy up, remove unreachable condition
faster getKey() helper
add test
perf test tweaks etc
Merge branch 'dev' into gh-1465