Code cleanup; fix some little bugs.