Make dialyzer happy

Use ets:tab() instead of ets:tid(), refine type specs such that the
code passes dialyzer with options -Wunmatched_returns,
-Werror_handling, -Wrace_conditions, -Wunderspecs