M and N in the transpose code were swapped. This was the most certain
reason for the bug that BUGGED me in the past few weeks :)