fix bug that prevented script from running first time