Add some rudimentary tests + fix some bugs