Finish the recursion in encode method