There is no need to do all this work if they share memory descriptors. Also, fix some minor whitespace and long lines.