code updated to handle no file field better