Added tests and fixed