Fixing bug in convert_to function