Added extra checks to avoid failures when missing data