Fix/search next

This only fixes the issue mentioned as [OpenProject](https://www.openproject.org/issues/2592). I had hoped to take the chance of cleaning up some more, but I unfortunately don't have the time.