Bug fixing + changed while loop to for loop, otherwise problems with sublb matrix