Close modals when clicking off them

Closes #3652