Turn the global mutex into instance variables

To fix #52