Rewrite safe_input() to reduce number of lines