refactor FSM, Load data, beautify code