debugged PSTH codes