Moved matrix creation to a function.  Increased speed.