added second argument to call to exist. this function is sometimes called thousands of times from within loops, and the function exist was by far the slowest execution time