Refactor javascript callbacks.