in reply to unknown syntax error

You're missing a '}' right above that elsif on line 60. The general style of deeply nested if statements can lead to these problems being hard to spot. You might want to think about how you can refactor the code a bit.