More tests, fixed some bugs