Clean up invalid references