Added some test, and done some fixing