Changed db to be global vairable, added documentation for different message types