Finished Databasefunction for queue, working on algorithm.