Refactor, use a functional style for models and controllers