Updated is_valid_path and command()