prevent race condition if init script is not done yet; refactoring