refactored to get it ready for code generation