refactored get function