i will do more cleanups for this script, if this patch is accepted.