Optimise matrix creation