Bug fix with logging