optimized the code and add statesproxy