Refactoring and security fixes in admin module