Remove unused code & add permissions check