Refactored listener and corrected html templates