Error fix

Old script with minor changes.