Are you sure that the problem isn't with the Matrix_program subroutine itself?