some refactoring done, more to come.
more refactoring.