Fix various next/prev page issues
Updates #30896
Code cleanup & reformatting (no ticket)
Use function abstraction layer (no ticket)