made scripts more robust