Refactor attendance logic