#1 code refactor for js