Various cleanup.

Added initial tests.