code cleanup and more logging
code cleanup