refactor some view code