Added checks for an empty vector before looking inside of it