rough draft of scalar filtering code