Fix JavaScript output and add logging