updated to use template and dynamic mapping