Moved database scanning code into a loader