It would be nicer to have `.next` and `.previous` API to clean this function up.