Cleaned up the code for the "closeKeyboardIfOpen" method