reorganized code; removed unused imports; added logging