Refactoring, adds more tests, and fixes some issues related to things not loading properly.