Move self.db to the top of the file