added better input handling