building matrix class