Remove repeating code
Improve error handling
Modify save roles and groups