Refactoring frontend js