I was thinking something more like this http://pastebin.mozilla.org/3079831 which imho is more readable, but feel free to choose what fits you best.

Extra tip: I'm doing the sorting based on `name`