General code improvements + database improvements