commit the part of the patches I've been using that were written by torford and gjmurphy