Added tests and examples; cleaned up code.