I've seen techniques similar to this in the past, and I know I'm going to "wish I could remember where I saw the code" at some stage in the future, so here it is for the BAS.

Thanks, Ayende.