moved security to db and added pagination