remove dead code & some refactoring