fixed a selection of bugs