fixed some bugs and locking problems