Optimized member function from exercise 2.2