Added some tests and fixes