Add some tests, fix some bugs + clean a few things