refactored code and added logic to read data off of queues