address comments - code cleanup, better log and error messages.