Fixing various modal/focus related bugs

Closes: #4809 #4951