Reworked approach given StackOverflow article