moved code from tpl to preprocessor