Wrapping all pre-processing functionality into a single function for convenience
Merging, to include Justin's bugfix