cleanup and some refactor