optimize debugger and add unit tests