Added Logging in and fixed errors