Fixed matrix transpose function