Most of script code finished

todo: IsCanonical; testing