Fixed bug in procedure for averaging multiple waves