Accepting list of files as well as a directory, with additional refactoring and testing