fixed some bugs. logging still missing.