Commented how my code in state.js works