a lot of bugs and a few fixes