used array_key_exists instead of in_array