Added empty check to handle race condition