Refactor view code