Lots of bugs fixed