Added database support and a few unit tests