Added tests and testing scripts.
Partial fixes.