Fix many issues and dak integration

I needed some of these changes to make the code work for me, others are just cosmetic or required to make the code better suited for integration into dak (for the last part, more changes need to be made)

Make sure you use the database more often, it is the best source for information you can get.