fixes some logical bugs in padMatrix