I'd restructure this code to do 

if (!ready) {
  // init config
  // register listener
  return;
}