add validation to prevent exceptions