refactor some code.  Fix reliability of filtering with jquery