Added some tests and fixed defects discovered while testing