Fixed lots of bugs