ok, lets start by fixing-up a syntax error in your code:

line 235: you have END IF instead of ENDIF