refactored functions to avoid out params