I battled with this sort of problem a few months ago and I spent some time yesterday putting up my solution onto the Albatross wiki. http://www.object-craft.com.au/projects/albatross/wiki/ExampleCode