Working filtering, still needs cleanup and optimization