Some refactoring to make it clearer where in the code everything goes.
A few changes to reflect libespm refactoring.