refactor code and clean up.