Simpler code to do the same thing; the trick is str