refactoring to use $osfamily and support custom templates