refactoring table.js