Better error logging with stack trace