Fixed bug, added mutex