change exists() function to synchronous function