Removes bad references