HUGE commit where the logic actually kind of works