Yep, we definitely have to refactor this, it's sort of embarrassing