Fix boolean logic bugs/confusions