Add mutex locking, doesn't work though