Trying to do some refactoring, to merge all of the common functionality.