use `elif val[-1] == ''` here