Fix various bugs so that the whole sum-prog type checks