refactored kernel codegen to compute steps outside of loop