Added Logging. And some cleaning