Fixed some issues concerninng the index.

Added some safety code that check if the index we are looking for is
out of range or not. It's more stable than the previous version.
Fixed some Index range issues.

Prevented some stuff from getting out the index. managed to work a bit
on the token dectection so that it gather more appropriately the tokens.