Added tests and fixed a few things