Fixed formatting for some functions in models and some refactoring