add variable cleanup supplied by maksqwe.  fix sign/unsigned warning.