Refactor code on views