Replace defer with scope_exit and fix uniforms