Refactor display code