Javascript refactoring in portfolio