refactor references() with visitor