Added debug and better "i" counter