fixing lots of small bugs