refactored code, returned by pointers