added 'perfect' solution