Cleaned the logic.