Added logging and fixed errors.