merge database code with IRC, cleanup