refactoring: because of strange results cause possibly by race condition made the script work in sequential way