minor optimization and refactoring of lessons code