First try that fails badly
Fix loop caused by wrong logic