refactor solution 2 to be a bit cleaner