Implement tail-call optimization