Added some tests and found some bugs :-)