More work and thought into the recursive function