refactoring for thread safety execution