add mutex and queue so that threads behave nicely