Some refactoring in models and scripts