Added database interaction code and appropriate tests. Also some tests for tickets.