Fixed bugs with matrices