Big credit to micah1_8 for this gem.