Fix duplicate code and fix XSS bug
Merge pull request #1 from PenguinPaul/master

Fix duplicate code and fix XSS bug