Added "use strict" and fixed undeclared variable errors.