removes invalid keys