Added average algorithm for testing