Extract matrix creation into private method