Removed the queuing logic and added db writes. The logic is sudo recursive and all around needs further improvement and refactoring.