tail call optimization

Implemented tail call optimization. Though I tried some times, failed to setup environment to build it so I've never tested the code, but I think it will work without problems.