reorganized some code.