Made things a little bit more object oriented

Put everything inside a Chainer class, which essentially just means that
the database is only connected to once no matter what, which should save
a little time at the cost of a little memory