made pagination code somewhat prettier