fixing some nasty bugs, this what you get for no tests with hacks