Fixed a bug to select the right type