Fixed recursion bug. Moved check_valid_input function into tools module