fix lots of bugs