UNFINISHED big refactor to split out into multiple files