Adding a search-for-next-cap function