optimize state machine, add minor css fixes