tail call optimization

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