Break out sanitisation of filter function into separate function