Simpler code that works