refactored collapse.js change

as per suggestion (though had to add the semicolon after the var line,
as otherwise one of the unit tests failed ?!)