Not sure how to close this question without a comment, but i've managed to get a solution working with the code used at the top of the question, in the Edit section.