some refactor and clean up