This works (worked) and should be a decent starting point:
The example should be fleshed out with a tad more functionality, of course.