Adding models and refactoring views to use models instead of writting sql