fix a set of bugs