Added safeguard to prevent crash