Massive cleanup, functions for initialising database.