fixed a lot of bugs (and there are more)