Move "common" objects into separate modules

This factoring makes the dependencies of each module more clear and
easier to manage. It also allows the modules to be imported (and tested)
directly.