Added pagination,  removed unnecessary code