Fixed bug from commit b0fe9ab

Should probably take a closer at locking in other places where necessary