updated deprecated syntax and added ruby friendly average method