Refactor javascript part