Fix function definition which caused state bug