This is the code we used on the BPS after the 2012 ASC race.  Written by Jimmy Frilling.