Separated logic from handler in JS client.