improved mean function, some comments