copy a bunch of framework code from bsbe project (i sure wish this were a library)