permission changes and fixed variable scope