slight perf tweak + proper locking