You might also find this example file and discussion from last week useful, it covers similar ground.