Fixing undefined bug