Refactoring to move redundant code and added sanity check for doublet filenames in package