Fix logging and debugging