Hopefully the attached code will help.