Added der and val method for matrices.
Cleaner code.