updated matrix function