better cleanup, made GetDiff function script-local