Refactor ufunc api and code generation