KH-213: Improved version of the script