remove unused local vars and redundant var