Fix function permissions, add comments