Added check to ensure the resource exists, preventing unexpected NullPointerException