Refactor javascript.