Allow to debug
Added tests and fixed some errors