refactor some code & test for jslint