fix bugs in generating hopping matrices