Also `lists:all/2` should be called before `lists:reverse/1` and `lists:ukeysort/2`, this way we get a function_clause for improper lists and arbitrary terms.

And instead of matching on a `lists:all/2` call, you could use `lists:foreach/2` with `fun ({_,_}) -> ok end`.