added file sorting to db quering. removed unnecessary db querying when processing unfinished submissions.