Added extra checks to prevent notices