P021: improved solution