Add helper functions for problems 8 to 10