Added some missing tests, and fixed some bugs