move table out of function
factor together permission lookups
break up long function
reindent