Miscellaneous changes to algorithm etc.