some code clean up and refactor.