fix bugs in patmat