improved solution