I've changed the functions for matrices