Some performance improvements. Shape distance changed to be exactly like the one in the paper