Add lock around hook apply function