fixing all sorts of bugs