Refactored helper to share code.