separate logic of matrix filling