Restructure mode-statemachine and fixed few tabbing problems