added endState function definition