Added some tests and minor fixes