Add test case
Improve tests and logging