A copy and slightly modify solution based on the example provied