Refactor convert function to use a map