code tidy + add new pagination functions