Move some of the bootstrap out of raw SQL