setSafe for setting keys safely on non-existent filters
Generalise safe functions and code reorganisation