Fixed a load of bugs