added security and sorting