refactoring of convert()