finished code for 3-way filter