a bit longwinded, but clear smart solution