Refactor redundant view code