Added tests, fixed some broken semantics.