improved logging and thread handling