#27 refactoring function for generc code generation