Added check for whether declaration exists to avoid error on losing focus