added some state handling