Added Logging, fixed bug