Fix lookback

Andrew, I think this is a fix but haven't been able to test it. Please have a look, and run tests before merging! Thanks!