fixing lots of bugs