=Updated to move some helper functions out into util.js