fix bunch of bugs