typos fixed and logging improved