Seems like this function is generic enough to go into kalite.js.