Fixing undefined bug the right way