Refactored into function