Implement SPSA with debugging