Added tests to cover most of it