Refactored, added recursive calls