rolled back most changes for scratch, but left a couple bits in for convenience otherwise