file load refactoring and bugfixing