fixing undefined bug