More file loading code and various bugfixes.