Fixed completely incorrect logic.