refactored/improved wrap_data