solution for ex6 (now without unnecessary overhead)