WIP: Night mode refactoring

Currently incomplete and still being tested, but here's the WIP refactoring of the night mode module. Will fix #1155 once complete.