some refactor and formatting