Web UI: refactored JS code to be modular