improve matrix creation