Add If and fix some bugs