[apiserver] refactored for better thread safety;