made get_width_of_terminal its own function and catch cases where it does not work