Fixed crash when closing the last image tab.
Fixed duplication of background layer when switching between image tabs.