Some source code patches for V2.31

Nice improvement on the origional. Thanks for posting