thats for all the suggestions and help! I think in the end it was a stray 'end' that was causing the errors, and i was looking for something more complicated. apologies for not checking my code more thoroughly!