Update utilities.js

added dynamic error checking function