Start testing and factoring.

A bunch of small improvments, including a start to unit tests and a removal of all tab characters.