code cleanup and implemented logging :cop: