It doesn't look any of your functions have end
, fix that first. If you properly indent your code you will see this.
You also have while count < length do
with an else
block. AFAIK this is not valid syntax (never seen it and just checked online ref manual and wiki). It is not clear whether you meant if count < length do
, but if really meant while
then replacing else
by end
doesn't look right either. Take a closer look at that section of code.