added missing end to if block