Check if res == nil before accessing kind_of?, please, since res can be nil