Thanks both, I've got it working
I used mk_1's aproach since it seems to be the most elegant way to do it.