a more intuitive recursive solution