First attempt at implementing code generation described in feature #2