remove most of the locking
fix compile bugs