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!

Update: Managed to run tests (in python) and it seems OK.