The basic algorithm looks OK, but you should probably try to use the general functions already available in lvm_tools.sh (part of the partman-lvm package) instead of the direct calls to pvs and vgs.
I begin at the end, since that was the easy part.Attached is a patch doing the same, but using the functions from lvm_tools.sh I might give a shot at the other issues too, but since i am mostly fumbeling around it may take quite some time.
Ronny Aasen