Updated populate function to keep track of current page