small refactors to js code