midnight refactor