try to implement tail call optimization, but idk how