unnecessary copies eliminated in scalar filter and filter function put in separate header