refactor component.js and its testing