some cleanup and refactor.