refactor view code