add matrix dealing