Added boundary check on tokens