Optimizations in tail calls

Review by @gkossakowski