Fix bug in expandBackwards/expandForwards