Add over quota check.

This comes with a large amount of refactoring.