[WIP] Refactor the fuck out of this.