Added tail recursive solution