WIP messages: general refactoring, fixes and improvements

`"""API to interact with the database."""`