Logic fixes