add automatic removal of old states
fix build