Another rewrite of the Pulses code, everything pretty much optimized