Further improvements to the code.

Code formating in accordance with Coding Style.
More tests.
Integration of recent code changes from ayastreb and weierophinney.
Even more tests and test data.