Abstract similar code used when loading saves or loading classes

Fixes #1046