Dismiss keyboard when tapped outside, fixed a few edge cases