IIF and refactoring

IIF avoid polluting global scope
several jshint fixes
refactor