[PATCH 5/5] compute next and previous window with modulo arithmetic