change matrix building method