Clean up JS to avoid callback hell.