Some addition for security and additional refactoring