Refactoring server side handling of scanned file