An alist associates keys with values (http://www.gnu.org/software/emacs/manual/html_node/elisp/Association-Lists.html). You're using plain nested lists. Maybe the use of `plist`s would simplify the overall code as you won't have to do length checks.