updated with some refactor.