Greatly improve type checking of select, and mult,count,add and friends
Fix two bugs