Refactored frame creation logic