Added the complex pagination method