Cleaned up filter matching logic, added more documentation