Added tests, fixed some minor issues