improved solution 1