Fixed logic flaws