Added check to ensure image ref is not null