Refactor to limit scope of two helper functions