Moved back to Arduino functions, assignments for debugging, reordered states.