multiple bug fixes, logging imrovement