So, does the code posted above solve your issue?