Fixed exception, made looping better.