remove unused var and do some refactoring