refactoring to handle references