added check for permissions to see stats (closes #1) and refactorings