moved database code to a goroutine