Add schemas code, second attempt.

Can we factor out these operations since they are both identical for clarity?