State machine rewritten, compiles, WIP