added logging, some tests. doesn't work yet.