reafctoring. add needed synchronization.