refactoring to reflect new architecture.
cleanup and refactoring.