Implemented functions code generation and improved granularity