added recursive solution