Added pthread mutexs to prevent parallel access of balance