updated with solution II