reorganizing logic for xcode to work properly