Bugfixes and better template function data flow