KH-213: Fixed bugs in the script