update recursive to stack and gaussian elimination