fixing logic flaw