Added null checks for imageFile and metadata