Fixes a few more bugs + adds more tests