further refactoring of template functions also proposal 1 implemented with commented out old code, fixed #493 as well