Refactor tpl codes

I found some code repetitions and lack of arguments when I wrote #752. This fixes them
- Use indirect function instead of the same code copies
- Fix missing arguments of some test codes