Move functions out of loops.
Remove wrong escape sequences.
Add missing semicolon and remove one unneded semicolon.
Fix incorrect variable declaration.
Make jshint happy.