refactoring file compare logic