Better locking - fixed type error