Fix race condition when setting firebase listeners