Refactored template and view logic.