removing unused code
Removed dead code, added some permission checks