clean up a bit, fix state issues