Bunch of bug fixes.

Next up: improve dynamics.