refactoring conversion function