Refactored and improved hideSoftKeyboard()