Added more logging; code cleanup