Refactored add_spikes in an independent function.