Recursive solution, easier for understand