fully refactored using code generation