cleaned up the code, added util.maybeCall that calls a function if it exists