Fix potential mismatches of ets:lookup
Fix type comments. Add comments. Add tests from PR feedback.