added delay and average functions