minor improvement on document insert
fix mutex unlocking in wrong order