Refactor function usage to avoid code duplication