refactored lesson filter algorithm