This trips my cleverness meter. There is a lot going on here that wouldn't be obvious without looking at the code.