fixing a lot of bugs