stuff for cosmic ray rejection and averaging with rejection