Copied in the parts of my personal library that this code uses until I can
eliminate the dependencies