Fixed Bugs. Added Logging.