Added Peter's wonderful solution