reverted  previous changes. Began code refactoring.
bug fixes