Fixed bug in ExtendMatrix