Add some helper functions.
Refactor js code.