hacky tail-call optimization