deleted useless setType and reordered code