Sample code for jon post on stackoverlow