implemented a fix for data access in templated functions