Improving portability and additional template function (constrain).