Add some basic tests and fix some bugs