Logic fixes everywhere