major refactoring with class definitions and HAI namespace