add logging, some fixes