close modal properly when clicking on background