Fixed error when no document is selected