fixed lots of bugs