Added some tests and fixed a couple bugs