matrices: improve constructors code