added paginate function, apphook