Refactor plugin code and gem creation

Cleanup code to prepare for roles management