Move code to load from file and a few bugfixes, and prepare for better parsing