Config reference feature

This is pretty much a rebased and fixed version of #452. Ready to be merged.