Create a Preconditions class

Refactor precondition checking to use the new Preconditions class.