Fix various bugs.

Signed-off-by: Paul G <pg@example.com>