Imported a bunch of stuff from scratchpad.