Added a check to make sure the nextElementSibling exists