fixed a *lot* of bugs