Refactoring to everything, this is a partial commit.

SQL structure will be changed, as well as group permissions, and some
unit tests will be added.