some refactoring and clearer thinking.