Add broker code and improve db code
Make code prettier in db