fixed a load of bugs