Refactor code of model