This code is presented as is, with no guarantees of any kind.