Refactoring (with JSLint help)