added average_and_max function and implemented a counting function