Backing up new work on bracketing algorithm (not yet integrated into plugin - simply pasted at end for backup).