Code cleanup and null pointer check for closing machine editing form.