Fix a few bugs from typos and a logic flaw