Fixed #146. Added morer unittests and fixed outstanding errors.
Merge origin/master