refactored conversion function