Added average function