Refactored root permission code