Fixed a typo and a logic flaw