Reduce memory usage and remove unneeded transpose