use html instead of displaying it.
refactored controller reducing duplicate code