Again, seems like we could do much of this declaratively.